<template>
  <div class="site-footer">
    <div class="concat-us-inner container">
      <div class="concat-us-outer">
        <div class="concat-us-title">{{ $t("contactUs") }}</div>
        <div class="sany-yunlian">{{ $t("sanyYunlian") }}</div>
        <a class="record-number" href="https://beian.miit.gov.cn" target="_blank" v-if="locale == 'zh-CN'">{{ $t("recordNumber") }}</a>
        <div class="concat-us-item">
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/phone-icon.png" />
          <span>{{ $t("mobile") }}：+86 191 8699 3576</span>
        </div>
        <div class="concat-us-item">
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/whatApp-icon.png" />
          <span>{{ $t("whatsapp") }}：+86 191 8699 3576</span>
        </div>
        <div class="concat-us-item">
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/email-icon.png" />
          <span>{{ $t("email") }}：sanyyunlian@gmail.com</span>
        </div>
        <div class="concat-us-item">
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/address-icon.png" />
          <span>{{ $t("companyAddress") }}</span>
        </div>
        <div class="info-share" v-if="locale == 'en-US'">
          <a href="https://www.facebook.com/sanyyunlian" title="facebook" target="_blank">
            <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/facebook.png" />
          </a>
          <a href="https://www.tiktok.com/@sany_yunlian" title="tiktok" target="_blank">
            <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/tiktok.png" />
          </a>
          <a href="https://www.youtube.com/@SanyYunlianUsedmachine" title="youtube" target="_blank">
            <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/youtube.png" />
          </a>
          <a href="https://www.instagram.com/sanyyunlian" title="instagram" target="_blank">
            <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/instagram.png" />
          </a>
        </div>
      </div>
      <div class="concat-us-outer">
        <div class="concat-us-title">{{ $t("menu") }}</div>
        <div class="jump-link">
          <a href="/home" :title="`${$t('topbar')[0]}`">{{ $t("topbar")[0] }}</a>
          <a href="/used-machine/excavator-47" :title="`${$t('topbar')[1]}`">{{ $t("topbar")[1] }}</a>
          <a href="/products" :title="`${$t('topbar')[2]}`">{{ $t("topbar")[2] }}</a>
          <a href="/find-car" :title="`${$t('topbar')[2]}`">{{ $t("topbar")[3] }}</a>
          <a href="/news" :title="`${$t('topbar')[3]}`">{{ $t("topbar")[4] }}</a>
          <a href="/about-us" :title="`${$t('topbar')[4]}`">{{ $t("topbar")[5] }}</a>
        </div>
      </div>
      <div class="concat-us-outer">
        <div class="concat-us-title">{{ $t("sendInquiry") }}</div>
        <div class="info-tips">{{ $t("inquiryDec") }}</div>
        <el-form :model="form" :rules="rules" ref="rulesForm">
          <div class="info-rows">
            <el-form-item prop="userName">
              <el-input v-model="form.userName" :placeholder="$t('userName')"></el-input>
            </el-form-item>
            <el-form-item prop="userPhone" v-if="locale == 'zh-CN'">
              <el-input v-model="form.userPhone" placeholder="手机号"></el-input>
            </el-form-item>
            <el-form-item prop="emailAddress" v-else>
              <el-input v-model="form.emailAddress" placeholder="E-mail"></el-input>
            </el-form-item>
          </div>
          <el-form-item prop="otherInfo">
            <el-input type="textarea" :rows="2" :placeholder="$t('massage')" v-model="form.otherInfo"> </el-input>
          </el-form-item>
        </el-form>
        <div class="submit-btn" @click="handleConfirm">{{ $t("send") }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex"
export default {
  props: {},
  data() {
    return {
      form: {
        userName: "", //姓名
        userPhone: "", //手机号
        emailAddress: "", //邮箱地址
        otherInfo: "" //留言内容
      },
      rules: {
        userName: [{ required: true, trigger: "blur", message: this.$i18n.t("userNameTip") }],
        userPhone: [{ required: true, trigger: "blur", message: "请填写手机号" }],
        emailAddress: [{ required: true, trigger: "blur", message: "This field is required" }],
        otherInfo: [{ required: true, trigger: "blur", message: this.$i18n.t("otherInfoTip") }]
      }
    }
  },
  mounted() {},
  computed: { ...mapState(["locale"]) },
  components: {},
  methods: {
    removeEmptyValues(obj) {
      Object.keys(obj).forEach((key) => {
        if (obj[key] === null || obj[key] === undefined || obj[key] === "") {
          delete obj[key]
        }
      })
      return obj
    },
    async handleConfirm() {
      this.$refs.rulesForm.validate((valid) => {
        if (valid) {
          let cleanedObject = this.removeEmptyValues(this.form)
          this.$api.addClue({ ...cleanedObject }).then((res) => {
            this.$message.success(this.$i18n.t("submittedSuccessfully"))
            setTimeout(() => {
              location.reload()
            }, 1500)
          })
        } else {
          console.log("error submit!!")
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.site-footer {
  height: 340px;
  background: #363738;
  .concat-us-inner {
    height: 100%;
    display: flex;
    justify-content: space-between;
    padding: 35px 0;
    box-sizing: border-box;
    .concat-us-outer {
      .jump-link {
        display: flex;
        flex-direction: column;
        a {
          font-size: 16px;
          font-weight: 400;
          color: #fff;
          line-height: 16px;
          margin-bottom: 20px;
          text-decoration: underline;
        }
      }
      .concat-us-title {
        font-family: Alibaba-PuHuiTi, Alibaba-PuHuiTi;
        font-size: 22px;
        font-weight: 600;
        color: #fff;
        line-height: 30px;
        margin-bottom: 10px;
      }
      .sany-yunlian {
        font-size: 18px;
        font-weight: 400;
        color: #fff;
        margin-bottom: 10px;
      }
      .record-number {
        font-size: 16px;
        font-weight: 400;
        color: #fff;
        line-height: 20px;
        margin-bottom: 10px;
      }
      .concat-us-item {
        display: flex;
        margin-top: 10px;
        img {
          width: 20px;
          height: 20px;
        }
        span {
          width: 360px;
          font-size: 16px;
          font-weight: 400;
          color: #fff;
          line-height: 20px;
          margin-left: 10px;
        }
      }
      .info-share {
        display: flex;
        align-items: center;
        margin-top: 15px;
        box-sizing: border-box;
        img {
          width: 35px;
          height: 35px;
          cursor: pointer;
        }
      }
      .info-tips {
        width: 450px;
        font-size: 16px;
        font-weight: 400;
        color: #fff;
        line-height: 20px;
        margin-bottom: 10px;
      }
      .info-rows {
        display: flex;
        align-items: center;
        justify-content: space-between;
        ::v-deep .el-input__inner {
          width: 220px;
        }
      }
      .el-textarea {
        width: 100%;
        ::v-deep .el-textarea__inner {
          height: 60px;
        }
      }
      .submit-btn {
        width: 80px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background: #d71519;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 16px;
        color: #fff;
        cursor: pointer;
      }
    }
  }
}
</style>
